/*

    Kudos to KayNine for the robot ragdoll demo used as the basis for much of
    this code
*/

#ifndef ODN_MODELBIT_H
#define ODN_MODELBIT_H

#include <opal\opal.h>
#include <ogre\Ogre.h>

#include "ODN_Maths.h"
#include "ODN_Containers.h"

namespace ouden {


/*
    Class representing a physical segment of an animated Entity.
    Essentially it links an opal solid to an ogre node.
*/

/*
    TODO: consider linking model bits as nodes following the ogre skeletal structure

*/

class CModelBit
{
	public:
		CModelBit(opal::Solid* pSolid, Ogre::Bone* pBone);
		CModelBit(Ogre::Node* pBone, float boneRadius, CModelBit* parent, bool recursive = true);   // Create a model bit using a default solid (capsule)
		virtual ~CModelBit();

		opal::Solid* 		getSolid() 			{ return m_pSolid; }
		Ogre::Node* 		getNode() 			{ return m_pNode; }

		//Ensures the solid and the node stay together
		//Called by parent model entity
		//TODO: Code this

        void snapSolidToNode();
        void snapNodeToSolid();
        void blendSolidToNode();

        CModelBit* getChild(int num) { return children[num]; }


	protected:

	private:

		//Physical solid linked to bone
		opal::Solid* 		m_pSolid;
		opal::Joint*        m_pJoint;
		Ogre::Node*         m_pNode;
		Ogre::Quaternion    relative;
		Ogre::Quaternion    q;            // Just to reduce memory reallocations

        CModelBit* m_pParent;
		Array<CModelBit*> children;

};

} //namespace ouden

#endif // ODN_MODELBIT_H
